package filter;


import javax.servlet.FilterChain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.UserObject;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * <p>
 * 画面转移的进行的验证处理。
 * 登录状态的根据<code>UserInfo</code>是否存在来判定。
 * </p>
 * @author ben
 *
 */
public class SessionFilter extends AbstractCheckFilter
{

    //[ソース診断対応 start]
    //logクラスは static final にする
    //private Log log = LogFactory.getLog( SessionFilter.class );
    private static final Log log = LogFactory.getLog( SessionFilter.class );
    //[ソース診断対応 end]

    @Override
    public boolean validate( HttpServletRequest request, HttpServletResponse response, FilterChain chain )
    {

        HttpSession session = request.getSession();

        UserObject uo = ( UserObject ) session.getAttribute( UserObject.USER_OBJECT_KEY );

        if ( log.isDebugEnabled() )
        {
            log.debug( "用户信息:[" + ToStringBuilder.reflectionToString( uo, ToStringStyle.SHORT_PREFIX_STYLE ) + "]" );
        }

        return uo != null && uo.getUserId() != null;
    }

}
